#!/usr/bin/python
# -*- coding: UTF-8 -*-

import time
import threading

def run(n, se):
    se.acquire()
    print("run the thread: %s" % n)
    # time.sleep(5)
    print('dada')
    time.sleep(5)
    se.release()

# 设置允许5个线程同时运行
semaphore = threading.BoundedSemaphore(5)
for i in range(20):
    t = threading.Thread(target=run, args=(i,semaphore))
    t.start()